package com.gxc.test;

import com.whalin.MemCached.MemCachedClient;
import com.whalin.MemCached.SockIOPool;

public class Memcached {

	private static SockIOPool pool = SockIOPool.getInstance();

	public static void test() {
		String[] servers = { "192.168.1.178:12405" };
		pool.setServers(servers);
		pool.setFailover(true);
		pool.setInitConn(10);
		pool.setMinConn(5);
		pool.setMaxConn(250);
		pool.setMaintSleep(30);
		pool.setNagle(false);
		pool.setSocketTO(3000);
		pool.setAliveCheck(true);
		pool.initialize();
		/* 建立MemcachedClient实例 */
		MemCachedClient memCachedClient = new MemCachedClient(true);
		for (int i = 0; i < 10; i++) {
			boolean success = memCachedClient.set("" + i, "Hello!");
			String result = (String) memCachedClient.get("" + i);
			System.out.println(String.format("set( %d ): %s", i, success));
			System.out.println(String.format("get( %d ): %s", i, result));
		}
	}

}
